home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
language
/
pcl_src.zoo
/
quadlap.lsp
< prev
next >
Wrap
Lisp/Scheme
|
1992-07-09
|
18KB
|
623 lines
;; -[Thu Mar 1 10:54:27 1990 by jkf]-
;; pcl to quad translation
;; $Header: quadlap.cl,v 1.1 90/02/21 08:54:42 jkf Exp Locker: jkf $
;;
;; copyright (c) 1990 Franz Inc.
;;
(in-package :compiler)
(defvar *arg-to-treg* nil)
(defvar *cvar-to-index* nil)
(defvar *reg-array* nil)
(defvar *closure-treg* nil)
(defvar *nargs-treg* nil)
(defvar *debug-sparc* nil)
(defmacro pcl-make-lambda (&key required)
`(list 'lambda nil :unknown-type 0 compiler::.function-level.
,required nil nil nil nil nil nil nil nil nil
nil 'compiler::none nil nil nil
nil nil nil nil nil nil 0 nil))
(defmacro pcl-make-varrec (&key name loc contour-level)
`(list ,name nil 0 nil ,loc nil t compiler::.function-level. nil nil :unknown-type nil nil ,contour-level))
(defmacro pcl-make-lap (&key lap constants cframe-size locals)
`(list nil ,constants ,lap nil nil ,cframe-size ,locals nil nil nil))
(defstruct (preg)
;; pseudo reg descritpor
treg ; associated treg
index ; :index if this is an index type reg
; :vector if this is a vector type reg
)
(defun pcl::excl-lap-closure-generator (closure-vars-names
arg-names
index-regs
vector-regs
fixnum-vector-regs
t-regs
lap-code)
(let ((function (pcl::excl-lap-closure-gen closure-vars-names
arg-names
index-regs
(append vector-regs fixnum-vector-regs)
t-regs
lap-code)))
#'(lambda (&rest closure-vals)
(insert-closure-vals function closure-vals))))
(defun pcl::excl-lap-closure-gen
(closure-vars-names arg-names index-regs vector-regs t-regs lap-code)
(let ((*quads* nil)
(*treg-num* 0)
(*all-tregs* nil)
(*bb-count* 0)
*treg-bv-size*
*treg-vector*
(*next-catch-frame* 0)
(*max-catch-frame* -1)
*catch-labels*
*top-label*
*mv-treg*
*mv-treg-target*
*zero-treg*
*nil-treg*
*bbs* *bb* lap
;; bbs
*cross-block-regs*
*const-tregs* *move-tregs*
*actuals*
*ignore-argcount*
*binds-specs*
*bvl-current-bv* ; for bitvector cacher
*bvl-used-bvs*
*bvl-index*
(*inhibit-call-count* t)
; this fcn
*arg-to-treg*
*cvar-to-index*
*reg-array*
minargs
maxargs
*closure-treg*
node
otherargregs
*nargs-treg*
)
(if* *debug-sparc*
then (format t ">>** << Generating sparc lap code~%"))
(setq *nil-treg*
#+allegro-v4.0 (new-reg :global t)
#-allegro-v4.0 (new-reg)
*mv-treg* (new-reg)
*mv-treg-target* (list *mv-treg*)
*zero-treg* (comp::new-reg))
; examine given args
(setq minargs 0 maxargs 0)
(let (requireds)
(dolist (arg arg-names)
(if* (eq '&rest arg)
then (setq maxargs nil)
else (if* (null arg)
then ; we want a name even though we won't use it
(setq arg (gensym)))
(incf minargs)
(incf maxargs)
(push (cons arg (new-reg)) *arg-to-treg*)
(push (pcl-make-varrec :name arg
:loc (cdr (car *arg-to-treg*))
:contour-level 0)
requireds)
))
(setq node (pcl-make-lambda :required (nreverse requireds))))
(setq *arg-to-treg* (nreverse *arg-to-treg*))
; build closure vector list
(let ((index -1))
(dolist (cvar closure-vars-names)
(push (cons cvar (incf index)) *cvar-to-index*)))
(let ((maxreg (max (apply #'max (cons -1 index-regs))
(apply #'max (cons -1 vector-regs))
(apply #'max (cons -1 t-regs)))))
(setq *reg-array* (make-array (1+ maxreg))))
(dolist (index index-regs)
(setf (svref *reg-array* index)
(make-preg :treg (new-reg)
:index :index)))
(dolist (vector vector-regs)
(setf (svref *reg-array* vector)
(make-preg :treg (new-reg)
:index :vector)))
(dolist (tr t-regs)
(setf (svref *reg-array* tr) (make-preg :treg (new-reg))))
(if* closure-vars-names
then (setq *closure-treg* (new-reg)))
(setq *nargs-treg* (new-reg))
;; (md-allocate-global-tregs)
; function entry
(qe nop :arg :first-block)
(qe entry)
(qe argcount :arg (list minargs maxargs))
(qe lambda :d (mapcar #'cdr *arg-to-treg*))
(qe register :arg :nargs :d (list *nargs-treg*))
(if* *closure-treg*
then ; put the first closure vector in *closure-treg*
(qe extract-closure-vec :d (list *closure-treg*))
(let ((offsetreg (new-reg)))
(qe const :arg (mdparam 'md-cons-car-adj) :d (list offsetreg))
(qe ref :u (list *closure-treg* offsetreg)
:d (list *closure-treg*)
:arg :long))
)
(excl-gen-quads lap-code)
(if* *debug-sparc*
then (do-quad-list (quad next *quads*)
(format t "~a~%" quad))
(format t "basic blocks~%"))
(setq *bbs* (qc-compute-basic-blocks *quads*))
(excl::target-class-case
((:r :m) (setq *actuals* (qc-compute-actuals *bbs*))))
(qc-live-variable-analysis *bbs*)
(setq *treg-bv-size* (* 16 (truncate (+ *treg-num* 15) 16)))
(qc-build-treg-vector)
(let ((*dump-bbs* nil)
(r::*local-regs*
; use the in registers that aren't in use
(append r::*local-regs*
(if* maxargs
then (nthcdr maxargs r::*in-regs* )))))
(unwind-protect
(progn
; machine specific code generation
(multiple-value-bind (lap-code literals size-struct locals)
#+(target-class r m e)
(progn
#+allegro-v4.0
(md-codegen node *bbs*
nil otherargregs)
#-allegro-v4.0
(md-codegen node *bbs*
*nil-treg* *mv-treg* *zero-treg*
nil otherargregs))
#-(target-class r m e) (md-codegen node *bbs*)
(setq lap
(pcl-make-lap :lap lap-code
:constants literals
:cframe-size size-struct
:locals locals)))
lap)
(giveback-bvs)))
#+ignore
(progn (format t "sparc code pre optimization~%")
(dolist (instr (lap-lap lap))
(format t "> ~a~%" instr)))
(md-optimize lap) ; peephole optimize
(if* *debug-sparc*
then (format t "sparc code post optimization~%")
(dolist (instr (lap-lap lap))
(format t "> ~a~%" instr)))
(md-assemble lap)
(setq last-lap lap)
(nl-runtime-make-a-fcnobj lap)))
(defun qe-slot-access (operand offset dest)
;; access a slot in a structure
(let ((temp (new-reg)))
(qe const :arg offset :d (list temp))
(qe ref :u (list (get-treg-of operand) temp)
:d (list (get-treg-of dest))
:arg :long)))
(defun get-treg-of (operand &optional res-operand)
;; get the appropriate treg for the operand
(let ((prefer-treg (and res-operand (simple-get-treg-of res-operand))))
(if* (numberp operand)
then (let ((treg (new-reg)))
(qe const :arg operand :d (list treg))
treg)
elseif (consp operand)
then (ecase (car operand)
(:reg
(preg-treg (svref *reg-array* (cadr operand))))
(:arg
(let ((x (cdr (assoc (cadr operand) *arg-to-treg* :test #'eq))))
(if* (null x)
then (error "where is arg ~s" operand)
else x)))
(:cvar
(let ((res-treg (or prefer-treg (new-reg)))
(temp-treg (new-reg)))
(qe const :arg (+ (mdparam 'md-svector-data0-adj)
(* 4 (cdr (assoc (cadr operand)
*cvar-to-index*
:test #'eq))))
:d (list temp-treg))
(qe ref :u (list *closure-treg* temp-treg)
:d (list res-treg)
:arg :long)
res-treg))
(:constant
(let ((treg (or prefer-treg (new-reg))))
(qe const :arg (if* (fixnump (cadr operand))
then (* 8 (cadr operand)) ; md!!
else (cadr operand))
:d (list treg))
treg))
(:index-constant
; operand invented by jkf to denote an index type constant
(let ((treg (or prefer-treg (new-reg))))
(qe const :arg (if* (fixnump (cadr operand))
then (* 4 (cadr operand)) ; md!!
else (cadr operand))
:d (list treg))
treg)))
else (error "bad operand: ~s" operand)